#ifndef __BL_PRECONFIG_H__
#define __BL_PRECONFIG_H__

#include "CompilerDefs.h"
#include <sys/types.h>


#if defined(__GNU_LIBRARY__)
#  include <endian.h>
#  include <byteswap.h>
#elif defined(__CRYPTLIB__)
#  if defined( INC_ALL )
#    include "crypt.h"
#  elif defined( INC_CHILD )
#    include "../crypt.h"
#  else
#    include "crypt.h"
#  endif
#  if defined(DATA_LITTLEENDIAN)
#    define PLATFORM_BYTE_ORDER SHA_LITTLE_ENDIAN
#  else
#    define PLATFORM_BYTE_ORDER SHA_BIG_ENDIAN
#  endif
#elif defined(_MSC_VER)
#  include <stdlib.h>
#elif !defined(WIN32)
#  include <stdlib.h>
#  if !defined (_ENDIAN_H)
#    include <sys/param.h>
#  else
#    include _ENDIAN_H
#  endif
#endif

#define BL_LITTLEENDIAN 0
#define BL_BIGENDIAN    1

#if !defined(BL_ENDIAN)
#  if defined(LITTLE_ENDIAN) || defined(BIG_ENDIAN)
#    if defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
#      if defined(BYTE_ORDER)
#        if   (BYTE_ORDER == LITTLE_ENDIAN)
#          define BL_ENDIAN BL_LITTLEENDIAN
#        elif (BYTE_ORDER == BIG_ENDIAN)
#          define BL_ENDIAN BL_BIGENDIAN
#        endif
#      endif
#    elif defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) 
#      define BL_ENDIAN BL_LITTLEENDIAN
#    elif !defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
#      define BL_ENDIAN BL_BIGENDIAN
#    endif
#  elif defined(_LITTLE_ENDIAN) || defined(_BIG_ENDIAN)
#    if defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
#      if defined(_BYTE_ORDER)
#        if   (_BYTE_ORDER == _LITTLE_ENDIAN)
#          define BL_ENDIAN BL_LITTLEENDIAN
#        elif (_BYTE_ORDER == _BIG_ENDIAN)
#          define BL_ENDIAN BL_BIGENDIAN
#        endif
#      endif
#    elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) 
#      define BL_ENDIAN BL_LITTLE_ENDIAN
#    elif !defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
#      define BL_ENDIAN BL_BIGENDIAN
#    endif
#  elif 0     /* **** EDIT HERE IF NECESSARY **** */
#    define BL_ENDIAN BL_LITTLEENDIAN
#  elif 0     /* **** EDIT HERE IF NECESSARY **** */
#    define BL_ENDIAN BL_BIGENDIAN
#  elif (('1234' >> 24) == '1')
#    define BL_ENDIAN BL_LITTLEENDIAN
#  elif (('4321' >> 24) == '1')
#    define BL_ENDIAN BL_BIGENDIAN
#  else
#    define BL_ENDIAN BL_LITTLEENDIAN
#  endif
#endif

#if COMPILER == COMPILER_MICROSOFT
typedef __int64            int64;
typedef __int32            int32;
typedef __int16            int16;
typedef __int8             int8;
typedef unsigned __int64   uint64;
typedef unsigned __int32   uint32;
typedef unsigned __int32   uint;
typedef unsigned __int16   uint16;
typedef unsigned __int8    uint8;
#else
typedef __int64_t   int64;
typedef __int32_t   int32;
typedef __int16_t   int16;
typedef __int8_t    int8;
typedef __uint32_t  uint;
typedef __uint64_t  uint64;
typedef __uint32_t  uint32;
typedef __uint16_t  uint16;
typedef __uint8_t   uint8;
typedef uint16      WORD;
typedef uint32      DWORD;
#endif
typedef uint64      OBJECT_HANDLE;
typedef unsigned char BYTE;

#endif